//
//  CaseProgressViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/24.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "CaseProgressViewController.h"
#import "CaseProgressView.h"
#import "GXXZViewController.h"
#import "ReleaseCaseViewController.h"
@interface CaseProgressViewController ()
@property(nonatomic,strong)CaseProgressView *aView;
@end

@implementation CaseProgressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"案件进度";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"更新" style:UIBarButtonItemStylePlain target:self action:@selector(pushToGX:)];
    
    _aView=[CaseProgressView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.top.mas_equalTo(0);
    }];
   
    _aView.viewController=self;
    [self LogingView];
    
    UIButton *btn=[UIButton new];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    btn.backgroundColor=_backgroundColor;
    [btn setTitle:@"程序完成" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(pushToJinDu:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)popVc{

    
    UINavigationController *navVC = self. navigationController;
    NSMutableArray *viewControllers = [ [NSMutableArray alloc] init];
    for (UIViewController *vc in [navVC viewControllers]){
        [viewControllers addObject:vc];
        if ([vc isKindOfClass: [ReleaseCaseViewController class]]) {
               break;
        }
        
    }
        [navVC setViewControllers:viewControllers animated:YES] ;

}

-(IBAction)pushToGX:(id)sender{
 
    NSString *litigation_id=[NSString stringWithFormat:@"%@",_litigation_id];
    GXXZViewController *gX=[[GXXZViewController alloc] init];
    gX.litigation_id=litigation_id;
    [ZQTools pushNextViewController:self andRootController:gX];
}

-(void)pushToJinDu:(UIButton *)btn{
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要结束程序" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleDefault   handler:nil];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"立即结束" style:UIAlertActionStyleDefault  handler:^(UIAlertAction * action) {
        [self pushToJinDu2];
    }];
    [alert addAction:defaultAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];

}


-(IBAction)pushToJinDu2{
    
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSString *user_id=[NSString stringWithFormat:@"%@",_litigation_id];
    NSNumber *waiter_id1=[userDic objectForKey:@"waiter_id"];
    NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id1];
    
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:waiter_id,@"waiter_id",user_id,@"litigation_id",token,@"token",@"1",@"user_role", nil];
    [ZQTools AFNPostDataUrl:@"waiter/litigation/end_litigation" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        [self popVc];
    } anderrorBlock:nil];
    
}

-(void)LogingView{
    
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *waiter_id2=[userDic objectForKey:@"waiter_id"];
    NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id2];
    NSString *user_id=[NSString stringWithFormat:@"%@",_litigation_id];
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:user_id,@"litigation_id",waiter_id,@"waiter_id",token,@"token",@"1",@"user_role", nil];
    [ZQTools AFNPostDataUrl:@"user/Litigation/schedule_list" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        _aView.titleArr=responseObject;
      [_aView creatView];
    } anderrorBlock:nil];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
